//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "EnergyVanillaSwap.h"
using namespace Cephei::QL::Experimental::Commodities;
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Money.h>
#include <gen/QL/Experimental/Commodities/UnitOfMeasure.h>
#include <gen/QL/Experimental/Commodities/CommodityIndex.h>
#include <gen/QL/Currency.h>
#include <gen/QL/Experimental/Commodities/PricingPeriod.h>
#include <gen/QL/Experimental/Commodities/CommodityType.h>
#include <gen/QL/Termstructures/YieldTermStructure.h>
#include <gen/QL/Experimental/Commodities/Quantity.h>
#include <gen/QL/Experimental/Commodities/PricingError.h>
#include <gen/QL/PricingEngine.h>
#include <gen/QL/Experimental/Commodities/EnergySwap.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL;
using namespace Cephei::QL::Termstructures;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::CEnergyVanillaSwap (boost::shared_ptr<QuantLib::EnergyVanillaSwap>& childNative, Object^ owner) : CEnergySwap(CEnergyVanillaSwap::typeid)
{
#ifdef HANDLE
	_phEnergyVanillaSwap = NULL;
#endif
	_ppEnergyVanillaSwap = &childNative;
    _ppEnergySwap = new boost::shared_ptr<QuantLib::EnergySwap> (boost::dynamic_pointer_cast<QuantLib::EnergySwap> (*_ppEnergyVanillaSwap));
}
Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::CEnergyVanillaSwap (QuantLib::EnergyVanillaSwap& childNative, Object^ owner) : CEnergySwap(CEnergyVanillaSwap::typeid)
{
#ifdef HANDLE
	_phEnergyVanillaSwap = NULL;
#endif
	_ppEnergyVanillaSwap = new boost::shared_ptr<QuantLib::EnergyVanillaSwap> (&childNative);
    _ppEnergySwap = new boost::shared_ptr<QuantLib::EnergySwap> (boost::dynamic_pointer_cast<QuantLib::EnergySwap> (*_ppEnergyVanillaSwap));
    _EnergyVanillaSwapOwner = owner;
    _EnergySwapOwner = owner;
}

Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::CEnergyVanillaSwap (CEnergyVanillaSwap^ copy) : CEnergySwap(CEnergyVanillaSwap::typeid)
{
#ifdef HANDLE
	_phEnergyVanillaSwap = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppEnergyVanillaSwap = new boost::shared_ptr<QuantLib::EnergyVanillaSwap> (copy->GetShared());
        _ppEnergySwap = new boost::shared_ptr<QuantLib::EnergySwap> (boost::dynamic_pointer_cast<QuantLib::EnergySwap> (*_ppEnergyVanillaSwap));
    }
}
Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::CEnergyVanillaSwap (System::Type^ t) : CEnergySwap(CEnergyVanillaSwap::typeid)
{
#ifdef HANDLE
	_phEnergyVanillaSwap = NULL;
#endif
	if (!t->IsSubclassOf(CEnergyVanillaSwap::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::CEnergyVanillaSwap (QuantLib::Handle<QuantLib::EnergyVanillaSwap>& childNative, Object^ owner)  : CEnergySwap(CEnergyVanillaSwap::typeid)
{
	_phEnergyVanillaSwap = &childNative;
	_ppEnergyVanillaSwap = &static_cast<boost::shared_ptr<QuantLib::EnergyVanillaSwap>>(childNative.currentLink());
    _ppEnergySwap = new boost::shared_ptr<QuantLib::EnergySwap> (boost::dynamic_pointer_cast<QuantLib::EnergySwap> (*_ppEnergyVanillaSwap));
    _EnergyVanillaSwapOwner = owner;
}
Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::CEnergyVanillaSwap (QuantLib::Handle<QuantLib::EnergyVanillaSwap> childNative)  : CEnergySwap(CEnergyVanillaSwap::typeid)
{
	_phEnergyVanillaSwap = &childNative;
	_ppEnergyVanillaSwap = &static_cast<boost::shared_ptr<QuantLib::EnergyVanillaSwap>>(childNative.currentLink());
    _ppEnergySwap = new boost::shared_ptr<QuantLib::EnergySwap> (boost::dynamic_pointer_cast<QuantLib::EnergySwap> (*_ppEnergyVanillaSwap));
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::CEnergyVanillaSwap (QuantLib::EnergyVanillaSwap childNative)  : CEnergySwap(CEnergyVanillaSwap::typeid)
{
#ifdef HANDLE
	_phEnergyVanillaSwap = NULL;
#endif
	_ppEnergyVanillaSwap = new boost::shared_ptr<QuantLib::EnergyVanillaSwap> (new QuantLib::EnergyVanillaSwap (childNative));
    _ppEnergySwap = new boost::shared_ptr<QuantLib::EnergySwap> (boost::dynamic_pointer_cast<QuantLib::EnergySwap> (*_ppEnergyVanillaSwap));
}
#endif

Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::~CEnergyVanillaSwap ()
{
    if (_ppEnergyVanillaSwap != NULL)
    {
	    delete _ppEnergyVanillaSwap;
        _ppEnergyVanillaSwap = NULL;
    }
}
Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::!CEnergyVanillaSwap ()
{
    if (_ppEnergyVanillaSwap != NULL)
    {
	    delete _ppEnergyVanillaSwap;
    }
}
QuantLib::EnergyVanillaSwap& Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::GetReference ()
{
    if (_ppEnergyVanillaSwap == NULL) throw gcnew NativeNullException ();
	return **_ppEnergyVanillaSwap;
}
boost::shared_ptr<QuantLib::EnergyVanillaSwap>& Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::GetShared ()
{
    if (_ppEnergyVanillaSwap == NULL) throw gcnew NativeNullException ();
	return *_ppEnergyVanillaSwap;
}
QuantLib::EnergyVanillaSwap* Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::GetPointer ()
{
    if (_ppEnergyVanillaSwap == NULL) throw gcnew NativeNullException ();
	return &**_ppEnergyVanillaSwap;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::EnergyVanillaSwap>& Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::GetHandle ()
{
	if (_phEnergyVanillaSwap == NULL)
	{
		_phEnergyVanillaSwap = new Handle<QuantLib::EnergyVanillaSwap> (*_ppEnergyVanillaSwap);
	}
	return *_phEnergyVanillaSwap;
}
#endif
bool Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::HasNative () 
{
	return (_ppEnergyVanillaSwap != NULL);
}

Cephei::QL::IMoney^ Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::FixedPrice::get ()
{
    try
    {
    	QuantLib::Money& _rv = (QuantLib::Money&)(*_ppEnergyVanillaSwap)->fixedPrice ( );   
        Cephei::QL::CMoney^ _nrv = gcnew Cephei::QL::CMoney (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Commodities::IUnitOfMeasure^ Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::FixedPriceUnitOfMeasure::get ()
{
    try
    {
    	QuantLib::UnitOfMeasure& _rv = (QuantLib::UnitOfMeasure&)(*_ppEnergyVanillaSwap)->fixedPriceUnitOfMeasure ( );   
        Cephei::QL::Experimental::Commodities::CUnitOfMeasure^ _nrv = gcnew Cephei::QL::Experimental::Commodities::CUnitOfMeasure (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Commodities::ICommodityIndex^ Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::Index::get ()
{
    try
    {
    	boost::shared_ptr<QuantLib::CommodityIndex>& _rv = (boost::shared_ptr<QuantLib::CommodityIndex>&)(*_ppEnergyVanillaSwap)->index ( );   
        Cephei::QL::Experimental::Commodities::CCommodityIndex^ _nrv = gcnew Cephei::QL::Experimental::Commodities::CCommodityIndex (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::IsExpired::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppEnergyVanillaSwap)->isExpired ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Int32 Cephei::QL::Experimental::Commodities::CEnergyVanillaSwap::PayReceive::get ()
{
    try
    {
    	QuantLib::Integer _rv = (QuantLib::Integer)(*_ppEnergyVanillaSwap)->payReceive ( );   
        Int32 _nrv = (Int32)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

